
/*
 * @author Javier A. Ramírez M.
 * jaramirez85@yahoo.es
 */

package com.jav.per;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;


public class PersisSetup {

    /**
     * 0: si, 1:no
     */
    private int verInforme;
    /**
     * 0: si, 1:no
     */
    private int verValores;
    /**
     * 0: Codigo, 1:Descripcion, 2:Bodega
     */
    private int ordenProductos;


    public int getOrdenProductos() {
        return ordenProductos;
    }

    public void setOrdenProductos(int ordenProductos) {
        this.ordenProductos = ordenProductos;
    }

    public int getVerInforme() {
        return verInforme;
    }

    public void setVerInforme(int verInforme) {
        this.verInforme = verInforme;
    }

    public int getVerValores() {
        return verValores;
    }

    public void setVerValores(int verValores) {
        this.verValores = verValores;
    }

    public boolean PermisoVistaValores(){
        return getVerValores() == 0 ? true : false;
    }

    public boolean PermisoInforme(){
        return getVerInforme() == 0 ? true : false;
    }

    public byte[] persist() throws IOException {
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        DataOutputStream dout = new DataOutputStream(bout);
        try{
            dout.writeInt(getVerInforme());
            dout.writeInt(getVerValores());
            dout.writeInt(getOrdenProductos());
            dout.flush();
        }
        finally{
            if(dout!= null){
                 dout.close();
            }
            if(bout!= null){
                 bout.close();
            }
        }
        return bout.toByteArray();

    }

    public void resurrect(byte[] by) throws IOException {
        ByteArrayInputStream bin = new ByteArrayInputStream(by);
        DataInputStream din = new DataInputStream(bin);
        setVerInforme(din.readInt());
        setVerValores(din.readInt());
        setOrdenProductos(din.readInt());
        bin.close();
        din.close();
    }


}
